<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib  prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="redis" uri="http://www.shopjsp.com/redisTag/functions" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="basePath" value="${redis:getSysConfig('base_path_back')}"/>
<script type="text/javascript">
    /**
     * 修改退货状态
     */
	<shiro:hasPermission name="back_gotoReturnsApplyPage_update">
    function updateReturnsState() {
        /**获取选中行的id**/
        var selectedRow = $("#tt").bootstrapTable('getSelections');
        if (selectedRow.length == 1) {
            if (selectedRow[0].applyState==2){/**审核状态 1、待处理；2、同意；3、拒绝**/
                $("#btn_updateReturnsState").attr("data-target", "#updateReturnsStateModal");/**选中了记录后才可打开对应的模态框**/
                /**隐藏域**/
                $("#update_returnsApplyId").val(selectedRow[0].returnsApplyId);
                /**可见表单控件**/
                $("#update_returnsApplyNo").empty().html(selectedRow[0].returnsApplyNo); /**退货申请编号**/
                /**退换货完成状态 0、待处理；1、商家退货中【已同意退货】；2、商家已收到用户退货；3、商家线下退款，退款中；4、线上、线下退款完成**/
                $("#returnsState_"+selectedRow[0].returnsState).attr("checked",true);
                <c:forEach items="${redis:getBasicKeyBook('returnsState')}" var="kb">
                if(selectedRow[0].returnsState>${kb.value}){
                    $("#returnsState_"+${kb.value}).hide();
                    $("#label_"+${kb.value}).hide();
                }else{
                    $("#returnsState_"+${kb.value}).show();
                    $("#label_"+${kb.value}).show();
                }
                </c:forEach>
			}else if (selectedRow[0].applyState==1){
                $("#btn_updateReturnsState").attr("data-target", "");/**条件不符不可打开模态框**/
                showMsg("审核待处理的不可更改退货状态！");
			}else if (selectedRow[0].applyState==3){
                $("#btn_updateReturnsState").attr("data-target", "");/**条件不符不可打开模态框**/
                showMsg("审核拒绝的不可更改退货状态！");
            }else {
                $("#btn_updateReturnsState").attr("data-target", "");/**条件不符不可打开模态框**/
                showMsg("审核状态为空不可更改退货状态！");
            }
        }else {
            $("#btn_updateReturnsState").attr("data-target", "");/**没有选中记录不可打开模态框**/
            showMsg("请选择一行记录！");
        }
    }
	</shiro:hasPermission>

    /**
     * 表单异步提交
     */
    function submitForm_updateReturnsState(){
        /**获取选中行的id**/
        var selectedRow = $("#tt").bootstrapTable('getSelections');
        if (selectedRow.length == 1) {
            if (selectedRow[0].returnsState==4){
                $("#validateBtn").hide();/**没有选中记录不可打开模态框**/
                showMsg("事务已完成，不需重复保存！");
			}else{
                var options = {
                    url: $("#form_updateReturnsState").attr("action"),
                    type: "post",
                    dataType: "json",
                    success: function (data) {
                        if (data.success == true) {
                            /** 先重置查询框的值**/
                            resetQueryForm();
                            /** 重新刷新列表数据**/
                            $("#tt").bootstrapTable('refresh');
                            /** 自动关闭弹出模态框窗口**/
                            $(".close").click();
                            showMsg("保存成功！");
                        } else {
                            showMsg("保存失败！");
                        }
                    }
                };
                $("#form_updateReturnsState").ajaxSubmit(options);
			}
        }
    }
</script>

<!--修改退货状态模态框（Modal） -->
<div class="modal fade" id="updateReturnsStateModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-backdrop="static">
	<div class="modal-dialog" style="width:70%">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
				<h5 class="modal-title" id="myModalLabel">修改退货状态</h5>
			</div>
			<div class="modal-body">
				<form id="form_updateReturnsState" method="post" action="${basePath}/back/returnsApply/updateReturnsState.sjson">
					<input id="update_returnsApplyId" type="hidden" name="returnsApplyId" value=""/>
					<table align="center" class="addOrEditTable table-bordered table" style="width:100%;">
						<tr>
							<td class="toright_td" width="150px">退货申请编号:</td>
							<td class="toleft_td">&nbsp;&nbsp;<span id="update_returnsApplyNo"></span></td>
						</tr>
						<tr>
							<td class="toright_td" width="150px"><span style="color:red">* </span>退货完成状态:&nbsp;&nbsp;</td>
							<td class="toleft_td">
								<ul style="margin-left:-55px;">
									<c:forEach items="${redis:getBasicKeyBook('returnsState')}" var="kb">
										<li style="list-style:none"><label class="checkbox-inline" style="vertical-align:middle; " id="label_${kb.value}"><input type="radio" id="returnsState_${kb.value}"  name="returnsState" value="${kb.value}"/>&nbsp;&nbsp;<span style="top: 5px;">${kb.name}</span></label></li>
									</c:forEach>
								</ul>
							</td>
						</tr>
					</table>
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" id="validateBtn" class="btn btn-primary" onclick="submitForm_updateReturnsState()">保存</button>
				<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
			</div>
		</div><!-- /.modal-content -->
	</div><!-- /.modal -->
</div>
